# Makefile for NETCONF project
#  
#   ncx directory

############### SOURCE PROFILE ##############################

SUBDIR_NM=ncx
SUBDIR_CPP=

############### TARGET PROFILE ##############################

TARGET=$(TBASE)/$(SUBDIR_NM)
LIB_INST=$(TBASE)/lib

ifdef FREEBSD
REAL_INST=$(DESTDIR)$(PREFIX)/lib
else
ifdef LIB64
REAL_INST=$(DESTDIR)$(PREFIX)/lib64
else
REAL_INST=$(DESTDIR)$(PREFIX)/lib
endif
endif

# if the target is DEBIAN or RPM package, then
# install the include files
REAL_INC_INST=$(DESTDIR)$(PREFIX)/include/yuma

######################### MAKE RULES ######################

all: ncxdummy ncxlib

#################### PLATFORM DEFINITIONS ############
include ../platform/platform.profile

################ DEPENDENCIES #########################
# depend rule must be included after the 'all' make rule

include ../platform/platform.profile.depend

ifdef DEBIAN
BLD_INCLUDES=
else
BLD_INCLUDES=includes
endif

test:

# build the library in any developer context
# and in the 1-pass RPM RELEASE build
# for ubunte RELEASE builds, only build if 
# this is real build not DEVELOPER
ifdef DEVELOPER
# just install the H files
install: includes
else
ifdef CROSS_TARGET
# don't install anything
install:
else
# normal build: 'make' or 'make STATIC=1'
install: $(BLD_INCLUDES)
# install static or dynamic libncx file
	mkdir -p $(REAL_INST)
	install -v $(OWNER) $(GRP) \
	$(LIB_INST)/lib$(SUBDIR_NM).$(LIBNCXSUFFIX) $(REAL_INST)
ifndef STATIC
# libncx.so --> libncx.so.M.N
# libncx.so.1 --> libncx.so.M.N
#ifndef MAC
#ifdef DEBIAN
#ifdef DEVELOPER
#	(cd $(REAL_INST); \
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX);\
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX).$(LIBNCX_MAJOR_VERSION))
#endif  # DEVELOPER
#else
#	(cd $(REAL_INST); \
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX);\
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX).$(LIBNCX_MAJOR_VERSION))
#endif  # DEBIAN
#endif  # MAC
ifndef FREEBSD
ifndef DESTDIR
ifndef MAC
# skip in MacOsX, RPM, FreeBSD and rest of debian fakeroot builds
	ldconfig $(REAL_INST)
endif  # MAC
endif  # DESTDIR
endif  # FREEBSD
endif  # STATIC
endif  # CROSS_TARGET
endif  # DEVELOPER

# 1 librarr uninstall rule for all variants
# TBD: uninstall includes
uninstall:
	rm -f $(REAL_INST)/lib$(SUBDIR_NM).$(LIBSUFFIX)*


# check which variant of the library to build
ifdef DEVELOPER
ncxlib:
else
ncxlib: $(LBASE)/lib$(SUBDIR_NM).$(LIBNCXSUFFIX)
ifndef STATIC
ifndef MAC
	(cd $(LBASE); ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
	lib$(SUBDIR_NM).$(LIBSUFFIX))
endif  # MAC
endif  # STATIC
endif  # DEVELOPER

# this dummy rule keeps make from deleting the $(OBJS) as
# intermediate files
ncxdummy: dependencies $(OBJS)

clean:
	rm -f $(OBJS) $(LBASE)/lib$(SUBDIR_NM).*

superclean:
	rm -f *~  $(DEPS) dependencies $(OBJS) \
	$(LBASE)/lib$(SUBDIR_NM).*

distclean: superclean

curversion.h:


ifdef WINDOWS
RDYNAMIC=
LC=
else
RDYNAMIC=-rdynamic
LC=-lc
endif

# this rule is ignored if STATIC=1; used only in linux
$(LBASE)/libncx.so.$(SOVERSION): $(OBJS)
ifdef FREEBSD
	$(CC) $(CFLAGS) -shared $(RDYNAMIC) -Wl,-soname,libncx.so.$(SOVERSION) \
	-o $@ $(OBJS) -L/usr/local/lib $(LC) -lxml2
else
	$(CC) $(CFLAGS) -shared $(RDYNAMIC) -Wl,-soname,libncx.so.$(SOVERSION) \
	-o $@ $(OBJS) $(LC) -lxml2
endif

# this rule is ignored if STATIC=1; used only on MacOSX
$(LBASE)/libncx.dylib: $(OBJS)
	$(CC) $(CFLAGS) -shared -dynamiclib -std=gnu99 -current_version \
	$(SOVERSION) \
	-undefined dynamic_lookup \
	-o $@ -install_name libncx.dylib $(OBJS) -lxml2


# install the H files into $DESTDIR/usr/include
includes:
	mkdir -p $(REAL_INC_INST)/ncx
	mkdir -p $(REAL_INC_INST)/platform
	cp *.h $(REAL_INC_INST)/ncx
	cp ../platform/procdefs.h $(REAL_INC_INST)/platform

.PHONY: includes ncxdummy ncxlib

# prevent the make program from choking on all the symbols
# that get generated from autogenerated make rules
.NOEXPORT:

ifndef DEVELOPER
include ./dependencies
endif

